package com.wangsb.utils;

import com.wangsb.domain.User;
import com.wangsb.service.ValidateExtensionService;
import com.wangsb.service.impl.ValidateExtensionServiceImpl;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.DeclareParents;
import org.springframework.stereotype.Component;

import java.util.IllformedLocaleException;

/**
 * 记录日志的工具类
 *
 * @author 黑马程序员
 * @Company http://www.itheima.com
 */
@Component
@Aspect//表明当前类是一个切面类
public class LogUtil {

    @DeclareParents(value = "com.wangsb.service.UserService+", defaultImpl = ValidateExtensionServiceImpl.class)
    ValidateExtensionService validateExtensionService;

    /**
     * 用于配置当前方法是一个前置通知
     */
    @Before("execution(* com.wangsb.service.impl.UserServiceImpl .*(..))&&this(validateExtensionService)&&args(user)")
    public void printLog(ValidateExtensionService validateExtensionService, User user) {

        if (validateExtensionService.checkUser(user)) {
            System.out.println("执行打印日志的功能，用户信息：" + user);
            return;
        }
        throw new IllformedLocaleException("参数异常");
    }

}
